<?php
namespace App\Controller;
use Swoole;
use App\Service\UserService;
class Base extends Swoole\Controller
{
    public $userinfo;
    public $token ;
    function __construct(\Swoole $swoole)
    {
        self::checkhead();
        parent::__construct($swoole);
    }

    public function checkhead()
    {
        $userService  = new UserService(0);

        $this->token = \Swoole::getInstance()->request->header['Token'];


        $this->userinfo = $userService->getUserLoginByToken($this->token);

        if(empty($this->userinfo)) {

            $ret = array(
                "errorcode" =>'0',
                'errmsg'=>"fail",
                'userinfo'=>''
            );
           // return json_encode($ret);
            \Swoole::getInstance()->http->response(json_encode($ret));
        }


    }
    function test()
    {
        return array('json' => 'swoole');
    }
}